﻿using DotNetCore.CAP.Dashboard.NodeDiscovery;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Common.CAP.Extensions
{
    public static class CAPExtensions
    {
        public static void AddCapService(this IServiceCollection services, IConfiguration config, string envName)
        {
            services.AddCap(option=>
            {
                option.UsePostgreSql(config["CAPSetting:pgsql"]);

                option.UseRabbitMQ(o=>
                {
                    o.HostName = config["CAPSetting:rabbitmq:host"];
                    o.UserName = config["CAPSetting:rabbitmq:user"];
                    o.Password = config["CAPSetting:rabbitmq:pwd"];
                    o.Port = 5673;
                });

                // 设置环境变量消息头
                option.TopicNamePrefix = envName;
                
                option.UseDashboard();
            });
        }

    }
}
